package com.xiangzi.dropwizard;

import java.util.Map;

import com.xiangzi.dropwizard.health.TemplateHealthCheck;
import com.xiangzi.dropwizard.resources.HelloWorldResource;
import com.xiangzi.dropwizard.resources.PersonResource;

import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.views.ViewBundle;

public class MyApplication extends Application<MyApplicationConfiguration> {

	public static void main(String[] args) throws Exception {
		new MyApplication().run(args);
	}

	@Override
	public String getName() {
		return "MyApplication";
	}
	
	@Override
	public void initialize(Bootstrap<MyApplicationConfiguration> bootstrap) {
		
		bootstrap.addBundle(new ViewBundle<MyApplicationConfiguration>() {
			@Override
			public Map<String, Map<String, String>> getViewConfiguration(MyApplicationConfiguration configuration) {
				return configuration.getViewRendererConfiguration();
			}
		});
		
	}
	
	@Override
	public void run(MyApplicationConfiguration configuration, Environment environment) {
		final HelloWorldResource resource = new HelloWorldResource(configuration.getTemplate(),
				configuration.getDefaultName());
		final TemplateHealthCheck healthCheck = new TemplateHealthCheck(configuration.getTemplate());

		environment.healthChecks().register("template", healthCheck);
		
		environment.jersey().register(resource);
		environment.jersey().register(new PersonResource());
		
	}

}
